<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <title>角色管理列表</title>
    <link rel="stylesheet" type="text/css" href="../lib/ext/resources/css/ext-all-neptune.css"/>
    <script type="text/javascript" src="../lib/ext/ext-all.js"></script>
    <script type="text/javascript" src="../lib/gf/tree_common_grid.js"></script>
</head>
<script type="text/javascript">

    //获取资源的父ID
    var parent_id = "0";
    var _urlparams = Ext.urlDecode(document.URL.split("?")[document.URL.split("?").length - 1]);
    if(_urlparams && _urlparams.parent_id){
        parent_id =  _urlparams.parent_id;
    }

    Ext.Loader.setConfig({enabled: true});

    Ext.Loader.setPath('Ext.ux', '/ext4/ux/');
    Ext.require([
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.toolbar.Paging',
        'Ext.ModelManager',
        'Ext.tip.QuickTipManager'
    ]);



    var win, searchForm;
    Ext.onReady(function () {
        Ext.define('RoleList', {
            extend: 'Ext.data.Model',
            fields: [
                '_id','role_code','role_name','role_desc'
            ],
            idProperty: '_id'
        });

        // create the Data Store
        var store = Ext.create('Ext.data.Store', {
            pageSize: 10,
            model: 'RoleList',
            remoteSort: true,
            proxy: {
                type: 'ajax',
                url: '/role/list?parent_id='+parent_id,
                reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'count'
                },
                simpleSortMode: true
            },
            sorters: [
                {
                    property: '_id'
                }
            ]
        });

        searchForm = new Ext.FormPanel({
            labelWidth: 75, // label settings here cascade unless overridden
            region: 'north',
            defaultType: 'textfield',
            items: [

            ]
        });

        var grid = Ext.create('Ext.grid.Panel', {
            store: store,
            loadMask: true,
            region: 'center',
            selModel: Ext.create('Ext.selection.CheckboxModel'),
            columns: [
                {
                    text: "_id",
                    dataIndex: '_id',
                    hidden: true
                },
                {
                    text: '角色编码',
                    dataIndex: 'role_code',
                    width : 300

                },
                {
                    text: '角色名称',
                    dataIndex: 'role_name',
                    width : 200

                },
                {
                    text: '角色描述',
                    dataIndex: 'role_desc',
                    width : 300

                }
            ],
            // paging bar on the bottom
            bbar: Ext.create('Ext.PagingToolbar', {
                store: store,
                displayInfo: true,
                displayMsg: 'Displaying {0} - {1} of {2}',
                emptyMsg: "没有数据！！！"

            }),
            tbar: [
                {
                    pressed: true,
                    text: "修  改",
                    icon : '../img/edit.png',
                    handler: function(){doEdit(grid,"/admin/role/add.html","修改角色",600,500)}
                },
                {
                    pressed: true,
                    icon : '../img/add.png',
                    text: "添  加",
                    handler: function(){doAdd("/admin/role/add.html?parent_id="+parent_id,"新建角色",600,500)}
                },
                {
                    pressed: true,
                    icon : '../img/delete.png',
                    text: "删  除",
                    handler: function(){doDel(grid,"/role/del",store)}
                },
                {
                    pressed: true,
                    icon : '../img/authority.png',
                    text: "授 权",
                    handler: function(){doAuth(grid,"/admin/role/auth.html","给角色授权",600,500)}
                },
                {
                    pressed: true,
                    icon : '../img/add_user.png',
                    text: "加入人员",
                    handler: function(){openWin(grid,"/admin/role/add_user.html","加入人员",600,500)}
                }

            ]
        });


        var viewport = new Ext.Viewport({
                    layout: 'border',
                    renderTo: "topic-grid",
                    items: [searchForm,grid]}
        );

        function doSearch(){
            store.loadPage(1,{params:searchForm.getValues()});
        }
        // trigger the data store load
        store.loadPage(1);
        window.refresh = function(){
            store.loadPage(1);
        }

        window.closeWin = function(){
            win.hide();
        }
    });
</script>
<body>
<div id="topic-grid" style="height: 1024px;width:100%"></div>
<p>The js is not minified so it is readable. See <a href="panel.js">panel.js</a>.</p>
</body>
</html>